//
//  LendPandectTableViewCell.m
//  ZYZB
//
//  Created by ENERGY on 2018/7/5.
//  Copyright © 2018年 ENERGY. All rights reserved.
//

#import "LendPandectTableViewCell.h"
@interface LendPandectTableViewCell()
@property (nonatomic, strong)UILabel * predictProfitTitleLab;//收益标题
@property (nonatomic, strong)UILabel * predictProfitContentLab;//收益数额
@property (nonatomic, strong)UILabel * deadlineLab;//距离到期
@property (nonatomic, strong)UILabel * projectContentLab;//标的名称
@property (nonatomic, strong)UIButton * rateBtn;//查看返息
@property (nonatomic, strong)UIButton * contractBtn;//查看合同
@property (nonatomic, strong)NSString * bidID;//标的ID
@end
@implementation LendPandectTableViewCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        self.contentView.backgroundColor = [UIColor whiteColor];
        __weak typeof (self)weakSelf = self;
        [self.contentView addSubview:self.predictProfitTitleLab];
        [self.contentView addSubview:self.predictProfitContentLab];
        [self.contentView addSubview:self.deadlineLab];
        [self.contentView addSubview:self.projectContentLab];
        [self.contentView addSubview:self.rateBtn];
        [self.contentView addSubview:self.contractBtn];
        
        [self.predictProfitTitleLab mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(weakSelf.contentView.mas_top).mas_offset(22/WIDTH_6_SCALE);
            make.left.equalTo(weakSelf.contentView.mas_left).mas_offset(19/WIDTH_6_SCALE);
            make.height.mas_equalTo(10/WIDTH_6_SCALE);
        }];
        [self.predictProfitContentLab mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(weakSelf.predictProfitTitleLab.mas_bottom).mas_offset(15/WIDTH_6_SCALE);
            make.left.equalTo(weakSelf.predictProfitTitleLab);
            make.height.mas_equalTo(25/WIDTH_6_SCALE);
        }];
        [self.deadlineLab mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(weakSelf.predictProfitTitleLab);
            make.top.equalTo(weakSelf.predictProfitContentLab.mas_bottom).mas_equalTo(12/WIDTH_6_SCALE);
            make.height.mas_equalTo(12/WIDTH_6_SCALE);
        }];
        [self.rateBtn mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.equalTo(weakSelf.contractBtn.mas_left).mas_equalTo(-22/WIDTH_6_SCALE);
            make.top.equalTo(weakSelf.contentView.mas_top).mas_equalTo(22/WIDTH_6_SCALE);
            make.width.mas_equalTo(64/WIDTH_6_SCALE);
            make.height.mas_equalTo(28/WIDTH_6_SCALE);
        }];
        [self.contractBtn mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.height.width.equalTo(weakSelf.rateBtn);
            make.right.equalTo(weakSelf.contentView.mas_right).mas_equalTo(-18/WIDTH_6_SCALE);
        }];
        [self.projectContentLab mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.equalTo(weakSelf.contractBtn.mas_right);
            make.height.mas_equalTo(12/WIDTH_6_SCALE);
            make.top.equalTo(weakSelf.contractBtn.mas_bottom).mas_equalTo(33/WIDTH_6_SCALE);
        }];
        UIView * lineView = [[UIView alloc] init];
        [self.contentView addSubview:lineView];
        lineView.backgroundColor = getColor(borderColor);
        [lineView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(weakSelf.contentView.mas_left).mas_equalTo(18/WIDTH_6_SCALE);
            make.right.equalTo(weakSelf.contentView.mas_right).mas_equalTo(-18/WIDTH_6_SCALE);
            make.top.equalTo(weakSelf.contentView.mas_bottom).mas_equalTo(-1/WIDTH_6_SCALE);
            make.height.mas_equalTo(1/WIDTH_6_SCALE);
        }];
    }return self;
}
#pragma mark - init
-  (UILabel *)predictProfitTitleLab{
    if (!_predictProfitTitleLab) {
        _predictProfitTitleLab = [[UILabel alloc] init];
        _predictProfitTitleLab.font = DEF_FontSize_10;
        _predictProfitTitleLab.textColor = [UIColor blackColor];
        _predictProfitTitleLab.textAlignment = NSTextAlignmentLeft;
        _predictProfitTitleLab.text = @"预期收益(元)";
    }return _predictProfitTitleLab;
}
-  (UILabel *)predictProfitContentLab{
    if (!_predictProfitContentLab) {
        _predictProfitContentLab = [[UILabel alloc] init];
        _predictProfitContentLab.font = [UIFont systemFontOfSize:24];
        _predictProfitContentLab.textColor = [UIColor blackColor];
        _predictProfitContentLab.textAlignment = NSTextAlignmentLeft;
        _predictProfitContentLab.text = @"13,660.73";
    }return _predictProfitContentLab;
}
-  (UILabel *)deadlineLab{
    if (!_deadlineLab) {
        _deadlineLab = [[UILabel alloc] init];
        _deadlineLab.font = DEF_FontSize_12;
        _deadlineLab.textColor = [UIColor blackColor];
        _deadlineLab.textAlignment = NSTextAlignmentLeft;
        _deadlineLab.text = @"距离到期还有365天";
    }return _deadlineLab;
}
-  (UILabel *)projectContentLab{
    if (!_projectContentLab) {
        _projectContentLab = [[UILabel alloc] init];
        _projectContentLab.font = DEF_FontSize_12;
        _projectContentLab.textColor = getColor(@"bdbdbd");
        _projectContentLab.textAlignment = NSTextAlignmentRight;
        _projectContentLab.text = @"【家家泰365天J16062141】";
    }return _projectContentLab;
}
- (UIButton *)rateBtn{
    if (!_rateBtn) {
        _rateBtn = [[UIButton alloc] init];
        _rateBtn.titleLabel.font = DEF_FontSize_10;
        [_rateBtn setTitle:@"查看返息" forState:UIControlStateNormal];
        [_rateBtn setBackgroundColor:[UIColor whiteColor]];
        [_rateBtn setTitleColor:getColor(@"ff8819") forState:UIControlStateNormal];
        _rateBtn.layer.borderColor = getColor(@"ff8819").CGColor;
        _rateBtn.layer.borderWidth = 1;
        _rateBtn.layer.cornerRadius = 6;
        _rateBtn.layer.masksToBounds = YES;
        [_rateBtn addTarget:self action:@selector(rateBtnClick:) forControlEvents:UIControlEventTouchUpInside];
    }
    return _rateBtn;
}
- (UIButton *)contractBtn{
    if (!_contractBtn) {
        _contractBtn = [[UIButton alloc] init];
        _contractBtn.titleLabel.font = DEF_FontSize_10;
        [_contractBtn setTitle:@"查看合同" forState:UIControlStateNormal];
        [_contractBtn setBackgroundColor:[UIColor whiteColor]];
        [_contractBtn setTitleColor:getColor(@"3675bd") forState:UIControlStateNormal];
        _contractBtn.layer.borderColor = getColor(@"3675bd").CGColor;
        _contractBtn.layer.borderWidth = 1;
        _contractBtn.layer.cornerRadius = 6;
        _contractBtn.layer.masksToBounds = YES;
        [_contractBtn addTarget:self action:@selector(contractBtnClick:) forControlEvents:UIControlEventTouchUpInside];
    }
    return _contractBtn;
}
- (void)setModel:(NSDictionary *)model{
    _model = model;
    self.predictProfitContentLab.text = model[@"earnings"];
    self.deadlineLab.text = [NSString stringWithFormat:@"距离到期还有%@天", model[@"day"]];
    self.projectContentLab.text = [NSString stringWithFormat:@"【%@】", model[@"productName"]];
    self.bidID = model[@"investmentid"];
}
- (void)rateBtnClick:(UIButton *)sender{
    if (self.rateBtnBlock) {
        self.rateBtnBlock(self.bidID);
    }
}
- (void)contractBtnClick:(UIButton *)sender{
    if (self.contractBtnBlock) {
        self.contractBtnBlock(self.bidID);
    }
}
@end
